package cn.myplus.examples.springbootswagger.users;

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController

@RestController
class UserController(private val userService: UserService) {

    private val logger: Logger = LoggerFactory.getLogger(UserController::class.java)

    @GetMapping("/users")
    fun getUsers(): ResponseEntity<MutableIterable<User>> {
        val users: MutableIterable<User> = userService.getUsers()
        return ResponseEntity<MutableIterable<User>>(users, HttpStatus.OK)
    }

    @GetMapping("/users/{id}")
    fun getUser(@PathVariable("id") id: String): User {
        logger.debug("pathVariable id :{}", id)
        val user = userService.getUserById(id)
        return user
    }

}